<?php


/**
 * cdn 加速
 */
function cdn($filepath)
{
    if (\Illuminate\Support\Facades\App::environment('production') && config('app.cdn_url')) {
        return config('app.cdn_url') . $filepath;
    } else {
        return asset($filepath);
    }
}

function mixcdn($filepath){
    if (\Illuminate\Support\Facades\App::environment('production')){
        return cdn(mix($filepath));
    }else{
        return mix($filepath);
    }
}

/**
 * 快速 设置 | 获取登录token的session
 * @param $t token 不设置为获取token
 * @return mixed
 */
function token($t = null){
    return is_null($t) ? session('winged_user_token') : session(['winged_user_token' => $t]);
}

/**
 * 快速设置｜获取已登录用户的userid
 * @param string $u
 * @return string
 */
function user_id($u = null){
    return is_null($u) ? session('winged_user_id') : session(['winged_user_id' => (string) $u]);
}

/**
 * @param null $u
 *　科室id
 * @return mixed
 */
function department_id($u = null){
   return is_null($u) ? session('winged_user_department_id') : session(['winged_user_department_id' => $u]);
}

/**
 * 快速设置|获取tenant的uuid
 * @param string $path
 * @return string
 */

function tenant($uuid = null){
    return is_null($uuid) ? session('tenant_id') : session(['tenant_id' => (string) $uuid]);
}
/**
 * 清空session中的用户信息
 */
function forget_session() {
    request()->session()->flush();
    request()->session()->save();
}

function winged_path($path = ''){
    return ucfirst(app_path('Winged')).($path ? DIRECTORY_SEPARATOR.$path : $path);
}

function console($obj)
{
    if (is_string($obj)) {
        $obj = json_encode(['obj' => $obj]);
    } else {
        $obj = json_encode($obj);
    }
    $h = <<<HTML
<!DOCTYPE html>
<html>
<head>
<script >
    console.log({$obj});	
</script>
</head>
<body>
</body>
</html>
HTML;
    echo $h;
}



function internel2public($url){
    return str_replace('-internal','',$url);
}